package com.example.day04.teachercode;

import java.util.Arrays;
import java.util.Date;

public class CustomerService {


    //添加订单信息
    public  void  add(Customer c,Order o){
        Order[]  temp=c.getOrders();
        if(temp==null){
            //初始化数组
            temp=new Order[0];
        }
        //数组扩容
        temp= Arrays.copyOf(temp,temp.length+1);

        temp[temp.length-1]=o;

        //元素添加完毕后订单存放数组要重新指向
        c.setOrders(temp);
    }

    //打印订单中的所有信息
    public  void printOrdermessage(Customer c){
        Order[] temp = c.getOrders();
        if(temp==null){
            System.out.println("订单信息为空。。。。。");
        }
        System.out.println("当期用户信息如下：");
        for (Order order : temp) {
            if(order.getStatus()!=3){
                System.out.println("\t"+order);
            }
        }

    }

     //根据订单号删除指定的元素
    public  void  deleteByno(Customer c,int no){

        Order[] temp=c.getOrders();
        if(temp==null){
            System.out.println("订单信息为空无法删除。。。。。。");
        }
        //被删除的订单状态设置为3
        for (Order order : temp) {
            if(order.getOrderNo()==no){
                order.setStatus(3);
            }
        }
        c.setOrders(temp);
    }



    //返回被删除的订单

    public  void  showDeleteList(Customer c){

        Order [] temp=c.getOrders();
        if(temp==null){
            System.out.println("订单为空。。。。。");
        }
        System.out.println("被删除的订单如下：");
        for (Order order : temp) {
            if(order.getStatus()==3){
                System.out.println("\t"+order);
            }
        }

    }
}

class  CustomerServiceTest{
    public static void main(String[] args) {
        Order order1=new Order(1,11,11.1,0,new Date());

        Order order2=new Order(2,22,22.2,0,new Date());
        Order order3=new Order(3,33,33.3,0,new Date());


        Customer customer=new Customer();

        CustomerService dir=new CustomerService();
        dir.add(customer,order1);
        dir.add(customer,order2);
        dir.add(customer,order3);

        dir.printOrdermessage(customer);

        dir.deleteByno(customer,11);

        dir.printOrdermessage(customer);


        dir.showDeleteList(customer);
    }


}

